<template>
	计划
	<view>
		<tui-calendar ref="calendar" lunar isFixed :type="type" @change="change"></tui-calendar>
	</view>
	<view>
		<tui-tabbar :current="currentTab" color="#AC9157" backgroundColor="#F8F4E1" :tabBar="tabBar"
			selectedColor="#AC9157" @click="tabbarSwitch">
		</tui-tabbar>
	</view>

</template>

<script>
	import {
		useCounterStore
	} from "../../../stores/counter.js";
	import {
		mapState,
		mapActions
	} from 'pinia';
	export default {
		data() {
			return {
				type:2,
				result: '',
				lunarResult:'',
				tabBar: [{
						pagePath: '/pages/index/list/index',
						text: '清单',
						iconPath: '/static/icon/qingdan.svg',
						selectedIconPath: '/static/icon/qingdan-s.png'
					},
					{
						pagePath: '/pages/index/plan/index',
						text: '计划',
						iconPath: '/static/icon/jihua.svg',
						selectedIconPath: '/static/icon/jihua-s.png'
					},
					{
						pagePath: '/pages/index/index',
						text: '选食材',
						iconPath: '/static/icon/cook.svg',
						hump: true,
						selectedIconPath: '/static/icon/cook-s.png'
					},
					{
						pagePath: '/pages/index/fridge/index',
						text: '冰箱',
						iconPath: '/static/icon/bingxiang.svg',
						selectedIconPath: '/static/icon/bingxiang-s.png'
					},
					{
						pagePath: '/pages/index/my/index',
						text: '我的',
						iconPath: '/static/icon/my.svg',
						selectedIconPath: '/static/icon/my-s.png',
						//num: 2,
						//isDot: true,
						//verify: true
					}
				],
				title: 'Hello'
			}
		},
		computed: {
			// 把pinia 的state映射到页面
			...mapState(useCounterStore, ["currentTab"])
			},
			onLoad() {
				uni.hideTabBar();
			},
			methods: {
				onpageshow(){
					this.selectDate()
				},
				//调用此方法打开日历，注：需等组件初始化后调用，避免在onLoad 中调用
				selectDate() {
					this.$refs.calendar && this.$refs.calendar.show();
				},
				change(e) {
					console.log(e);
					if (this.type == 1) {
						this.result = e.result + ' ' + e.week;
						let date = `${e.lunar.lYear}-${e.lunar.lMonth}-${e.lunar.lDay}`;
						this.lunarResult = `${e.lunar.gzYear}年，${e.lunar.gzMonth}月，${e.lunar.gzDay}日 。生肖：${e.lunar.Animal}。日期：${e.lunar.IMonthCn + e.lunar.IDayCn}(${date})`;
					} else {
						this.result = `${e.startDate} 至 ${e.endDate}`;
						let sDate = `${e.startLunar.IMonthCn + e.startLunar.IDayCn}(${e.startLunar.lYear}-${e.startLunar.lMonth}-${e.startLunar.lDay})`;
						let eDate = `${e.endLunar.IMonthCn + e.endLunar.IDayCn}(${e.endLunar.lYear}-${e.endLunar.lMonth}-${e.endLunar.lDay})`;
						this.lunarResult = `${sDate} 至 ${eDate}`;
					}
				},
				tabbarSwitch(e) {
					uni.switchTab({
						url: e.pagePath,
						success: () => { // 确保路由切换成功后再更新状态
							this.changeCurrentTab(e.index)
						}
					});
				},
				// 把pinia的方法映射到页面
				...mapActions(useCounterStore, ["changeCurrentTab"])
			}
		}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>